Source for file CreateFolder.php

Documentation is available at CreateFolder.php

  1. <?php /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2005 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *         http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *         http://www.fckeditor.net/
  10.  * 
  11.  * File Name: CreateFolder.php
  12.  *     Implements the CreateFolder command to make a new folder
  13.  *     in the current directory. Output is in XML.
  14.  * 
  15.  * File Authors:
  16.  *         Grant French (grant@mcpuk.net)
  17.  */
  18. class CreateFolder {
  19.     var $fckphp_config;
  20.     var $type;
  21.     var $cwd;
  22.     var $actual_cwd;
  23.     var $newfolder;
  24.     
  25.     function CreateFolder($fckphp_config,$type,$cwd{
  26.         $this->fckphp_config=$fckphp_config;
  27.         $this->type=$type;
  28.         $this->raw_cwd=$cwd;
  29.         $this->actual_cwd=str_replace("//","/",($this->fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd));
  30.         $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd));
  31.         $this->newfolder=str_replace(array("..","/"),"",$_GET['NewFolderName']);
  32.     }
  33.     
  34.     function checkFolderName($folderName{
  35.         
  36.         //Check the name is not too long
  37.         if (strlen($folderName)>$this->fckphp_config['MaxDirNameLength']return false;
  38.         
  39.         //Check that it only contains valid characters
  40.         for($i=0;$i<strlen($folderName);$i++if (!in_array(substr($folderName,$i,1),$this->fckphp_config['DirNameAllowedChars'])) return false;
  41.         
  42.         //If it got this far all is ok
  43.         return true;
  44.     }
  45.     
  46.     function run({
  47.         header ("content-type: text/xml");
  48.         echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
  49.         ?>
  50. <Connector command="CreateFolder" resourceType="<?php echo $this->type?>">
  51.     <CurrentFolder path="<?php echo $this->raw_cwd?>" url="<?php echo $this->actual_cwd?>" />
  52.     <?php
  53.         $newdir=str_replace("//","/",($this->real_cwd."/".$this->newfolder));
  54.         
  55.         //Check the new name
  56.         if ($this->checkFolderName($this->newfolder)) {
  57.             
  58.             //Check if it already exists
  59.             if (is_dir($newdir)) {
  60.                 $err_no=101//Folder already exists
  61.             else {
  62.                 
  63.                 //Check if we can create the directory here
  64.                 if (is_writeable($this->real_cwd)) {
  65.                     
  66.                     //Make the directory
  67.                     if (mkdir($newdir,0777)) {
  68.                         $err_no=0//Success
  69.                     else {
  70.                     
  71.                         $err_no=110//Unknown error
  72.                     }    
  73.                 else {
  74.                     $err_no=103//No permissions to create
  75.                 }
  76.             }
  77.         else {
  78.             $err_no=102//Invalid Folder Name
  79.         }
  80.         
  81.     ?>
  82.     <Error number="<?php echo "".$err_no?>" />
  83. </Connector>
  84.         <?php
  85.     }
  86. }
  87.  
  88. ?>

Documentation generated on Mon, 05 May 2008 16:19:03 +0400 by phpDocumentor 1.4.0